<?
include('wallet_db.html');
include('../rp2/global_functions.php');
?>
<html>
<head>
	<title>ResellersPanel</title>
	<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
	<style>
		body, input, select, textarea {
	                font-family: Tahoma, Helvetica, sans-serif;
                        font-size: 11px;
                }
		th {
			height: 20px;
			border:1px #FFC9AD solid;
			/*background-image: url(images/bg_th.jpg);*/
			background-position: top;
			background-repeat: repeat-x;
			font-family: Tahoma, Helvetica, sans-serif;
			font-size: 11px;
			font-weight: bold;
			color: #000000;
		}

		td {
			font-family: Tahoma, Helvetica, sans-serif;
                        font-size: 11px;
			border:1px #FFC9AD solid;
		}
		
		.row tr:hover{
			background-color:#FEFDE2;
		}		
		
		tr:hover{
			background-color:#FEFDE2;
		}		
		
		.cell {
			padding:0px;
			border-bottom:1px #FFC9AD solid;
			border-left:1px #FFC9AD solid;
			border-right:1px #FFC9AD solid;
		}
		
		.errormsg{
			color: #FF0000;
			font-size: 12pt;
			font-family: Verdana, Arial, Helvetica, sans-serif;
			width: 100%;
			font-weight: bold;
		}
		.price {
			font-size: 20px;
			font-weight: bold;
		}
		.small_price {
			font-size: 13px;
			font-weight: bold;
		}
    </style>
    <script language='JavaScript'>
    <!--
        function callOpener (url) {
                if (window.opener && !window.opener.closed) window.opener.location=url;
                else window.open(url,'subOpener','');
        }
    //-->
    </script>
</head>
<body onLoad='window.focus();'>
<div align='left'>
<p><font color='red'>ResellersPanel pre-defined plans</font></p>
<table border=0 class='bTable' cellspacing=0 cellpadding=3>
	<tr>
		<th rowspan='2' valign='top'>#</th>
		<th rowspan='2' valign='top'>Original<br> name</th>
		<th rowspan='2' valign='top'>Applicable<br> templates</th>
		<th colspan='3' valign='top'>Edit Plan</th>
		<th rowspan='2' valign='top'>Delete<br> Plan</th>
	</tr>
	<tr>
		<th valign='top'>Price</th>
		<th valign='top'>Name</th>
		<th valign='top'>Site Studio</th>
	</tr>
	<tr>
		<td>1</td>
		<td>Business</td>
		<td>#1 to #16</td>
		<td>yes</td>
		<td>yes</td>
		<td>on</td>
		<td>no</td>
	</tr>
	<tr>
		<td>2</td>
		<td>Corporate</td>
		<td>#1 to #16</td>
		<td>yes</td>
		<td>yes</td>
		<td>on</td>
		<td>no</td>
	</tr>
	<tr>
		<td>3</td>
		<td>Plan1</td>
		<td>#16</td>
		<td>yes</td>
		<td>yes</td>
		<td>on</td>
		<td>no</td>
	</tr>
	<tr>
		<td>4</td>
		<td>Plan2</td>
		<td>#16</td>
		<td>yes</td>
		<td>yes</td>
		<td>on</td>
		<td>no</td>
	</tr>
	<tr>
		<td>5</td>
		<td>Plan3</td>
		<td>#16</td>
		<td>yes</td>
		<td>yes</td>
		<td>on</td>
		<td>no</td>
	</tr>
</table>
<p>Current plans</p>
<table border=0 class='bTable' cellspacing=0 cellpadding=3>
	<tr>
		<th rowspan='2' valign='top'>#</th>
		<th rowspan='2' valign='top'>Current<br> name</th>
		<th rowspan='2' valign='top'>Applicable<br> templates</th>
		<th colspan='3' valign='top'>Edit Plan</th>
		<th rowspan='2' valign='top'>Delete<br> Plan</th>
		<th rowspan='2' valign='top'># of<br> clients</th>
	</tr>
	<tr>
		<th valign='top'>Price</th>
		<th valign='top'>Name</th>
		<th valign='top'>Site Studio</th>
	</tr>
<?
//------------------------------------------------------
	$sql['type']='SELECT';
	$sql['params']='product_id, name, plan_id';
	$sql['table']='products';
	$sql['where']="reseller_id='$id' AND type='plan' AND plan_id != 'a'";
	$sql['options']='ORDER BY seq';
	$sql['return']='struct';
//------------------------------------------------------
if (!$result=sql_exec($sql,$dbh81,'assoc')) {
	$errorMsg = translate('int_error');
	include_once('errorMsg.html');
	exit();
}
$i=1;
foreach ($result as $value) {
	unset($act,$tpl);
	//------------------------------------------------------
		$sql['type']='SELECT';
		$sql['params']='count(distinct pu.client_id) as count';
		$sql['table']='purchases as pu, products as pr, clients as c';
		$sql['where']="pr.product_id='".$value['product_id']."' and pr.product_id=pu.product_id and pu.client_id=c.client_id and c.blocked=0";
		$sql['options']='group by pu.product_id';
		$sql['return']='struct';
	//------------------------------------------------------
	if (!$result=sql_exec($sql,$dbh81,'assoc')) {
       		$count = '0';
	} else {
		$count = $result[0]['count'];
	}
	if ($value['plan_id'] == 'c' && $value['name'] == 'Corporate') {
		$tpl = "#1 to #16";
	} elseif ($value['plan_id'] == 'b' && $value['name'] == 'Business') {
		$tpl = '#1 to #16';
	} else {
		$tpl = '#16';
	}
	if ($count != 0) {
		$act = 'no';
	} else {
		$act = 'yes';
	}
	echo "<tr>
		<td>$i</td>
		<td>".$value['name']."</td>
		<td>$tpl</td>
		<td>yes</td>
		<td>$act</td>
		<td>$act</td>
		<td>$act</td>
		<td>$count</td>
	</tr>";
	$i++;
}
?>
</table>
<?
unset($result);
//------------------------------------------------------
	$sql['type']='SELECT';
	$sql['params']='product_id, name, plan_id';
	$sql['table']='products';
	$sql['where']="reseller_id='$id' AND type='plan' AND plan_id = 'a'";
	$sql['options']='ORDER BY seq';
	$sql['return']='struct';
//------------------------------------------------------
$result=sql_exec($sql,$dbh81,'assoc');
#$cnt = count($result);
#if ($cnt != 0) {
if (isset($result[0]['product_id'])) {
	?>
	<p><font color=blue>Your own custom-built plans</font></p>
	<table border=0 class='bTable' cellspacing=0 cellpadding=3>
	<tr>
		<th rowspan='2' valign='top'>#</th>
		<th rowspan='2' valign='top'>Current<br> name</th>
		<th rowspan='2' valign='top'>Applicable<br> templates</th>
		<th colspan='3' valign='top'>Edit Plan</th>
		<th rowspan='2' valign='top'>Delete<br> Plan</th>
		<th rowspan='2' valign='top'># of<br> clients</th>
	</tr>
	<tr>
		<th valign='top'>Price</th>
		<th valign='top'>Name</th>
		<th valign='top'>Site Studio</th>
	</tr>
	<?
	$i=1;
	foreach ($result as $value) {
		unset($act,$tpl);
		//------------------------------------------------------
			$sql['type']='SELECT';
			$sql['params']='count(distinct pu.client_id) as count';
			$sql['table']='purchases as pu, products as pr, clients as c';
			$sql['where']="pr.product_id='".$value['product_id']."' and pr.product_id=pu.product_id and pu.client_id=c.client_id and c.blocked=0";
			$sql['options']='group by pu.product_id';
			$sql['return']='struct';
		//------------------------------------------------------
		if (!$result=sql_exec($sql,$dbh81,'assoc')) {
       			$count = '0';
		} else {
			$count = $result[0]['count'];
		}

		if ($count != 0) {
			$act = 'no';
		} else {
			$act = 'yes';
		}
		echo "<tr>
			<td>$i</td>
			<td>".$value['name']."</td>
			<td>n/a</td>
			<td>yes</td>
			<td>$act</td>
			<td>$act</td>
			<td>$act</td>
			<td>$count</td>
		</tr>";
		$i++;
	}
	echo "</table>";
} else {
	echo "<p><font color='red'>You don't have custom build plans at the moment!</font></p>";
}
?>

<p>[<a href='#' onclick="window.close();">CLOSE THE WINDOW</a>]&nbsp;
[<a href='#' onclick="window.print();">PRINT THE WINDOW</a>]</p>
</div>
</body>
</html>
